import 'package:flutter/material.dart';
import 'package:zootix/models/zt_coin_goods.model.dart';
import 'package:zootix/services/zt_purchase.service.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';

class ZtGoodsItem extends StatelessWidget {
  final ZtCoinGoodsModel goodsItem;
  const ZtGoodsItem({super.key, required this.goodsItem});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        if (goodsItem.code != null) {
          ZtPurchaseService.to.applePay(goodsItem.code!, goodsItem.goodsId!);
        }
      },
      child: Container(
        height: ZtScreenAdaper.height(120),
        margin: EdgeInsets.symmetric(vertical: ZtScreenAdaper.height(10)),
        decoration: BoxDecoration(
            border: Border.all(color: const Color(0xFFFFCA41)),
            color: const Color(0xFFFFFCF8),
            borderRadius: BorderRadius.circular(15)),
        child: Column(children: [
          Row(
            children: [const Spacer(), _buildTags(goodsItem.tags)],
          ),
          Row(children: [
            SizedBox(
              width: ZtScreenAdaper.width(20),
            ),
            Image(
                height: ZtScreenAdaper.height(50),
                image: const AssetImage('assets/images/coin_icon.png')),
            SizedBox(
              width: ZtScreenAdaper.width(10),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '${goodsItem.exchangeCoin}',
                  style: TextStyle(
                      fontSize: ZtScreenAdaper.width(18),
                      color: const Color(0xFF523E0B),
                      fontWeight: FontWeight.bold),
                ),
                if ((goodsItem.discount ?? 0) > 0)
                  Text(
                    '${((goodsItem.discount ?? 0) * 100).toInt()}% off',
                    style: TextStyle(
                        fontSize: ZtScreenAdaper.width(13),
                        color: const Color(0XFFE37714),
                        fontWeight: FontWeight.bold),
                  ),
              ],
            ),
            const Spacer(),
            Text(
              '\$' + '${goodsItem.price}',
              style: TextStyle(
                  fontSize: ZtScreenAdaper.width(20),
                  color: const Color(0xFF202020),
                  fontWeight: FontWeight.bold),
            ),
            SizedBox(
              width: ZtScreenAdaper.width(10),
            ),
            if ((goodsItem.discount ?? 0) > 0 &&
                goodsItem.originalPrice != goodsItem.price)
              Text(
                '\$${goodsItem.originalPrice}',
                style: const TextStyle(
                  color: Color(
                    0xFFCCCCCC,
                  ),
                  decoration: TextDecoration.lineThrough,
                  decorationStyle: TextDecorationStyle.solid,
                ),
              ),
            SizedBox(
              width: ZtScreenAdaper.width(20),
            ),
          ])
        ]),
      ),
    );
  }

  Widget _buildTags(String? tags) {
    return tags == null
        ? Container(
            height: ZtScreenAdaper.height(35),
          )
        : Container(
            height: ZtScreenAdaper.height(35),
            alignment: Alignment.center,
            padding: EdgeInsets.symmetric(horizontal: ZtScreenAdaper.width(10)),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(ZtScreenAdaper.sp(15)),
                    topRight: Radius.circular(ZtScreenAdaper.sp(15))),
                gradient: const LinearGradient(
                    colors: [Color(0xFFFFED4A), Color(0xFFFFC42E)])),
            child: tags == 'Hot'
                ? Image(
                    height: ZtScreenAdaper.height(24),
                    image: const AssetImage('assets/images/good_hot.png'))
                : Text(
                    '$tags',
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                        fontSize: ZtScreenAdaper.sp(15)),
                  ),
          );
  }
}
